<template>
  <div class="logo">
    <router-link :to="{ path: '/' + currentApp }">
      <SvgIcon v-if="img == null" name="logo" />
      <a-image v-if="img != null" :width="40" :height="40" :src="img" :preview="false" />
      <h1 v-if="showTitle">{{ title }}</h1>
    </router-link>
  </div>
</template>

<script lang="ts" setup>
import { defineProps, getCurrentInstance, watch, ref } from 'vue'
import { currentApp } from '@/store/useSiteSettings'
import SvgIcon from '@/components/SvgIcon/index.vue'
const props = defineProps({ showTitle: { type: Boolean, required: false, default: true } })
const title = ref('Ant Design Pro')
const img = ref(null)
const context = getCurrentInstance()?.appContext.config.globalProperties
const loadAppInfo = () => {
  context.$api.GET('/realm/app/selectOneById?id=' + currentApp.value).then((res) => {
    title.value = res.data.name
    img.value = res.data.icon
  })
}
watch(
  () => currentApp.value,
  (val) => {
    loadAppInfo()
  }
)
loadAppInfo()
</script>
